package com.font.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.font.bean.*;
import com.font.mapper.WenMapper;
import com.font.service.WenService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * (Wen)表服务实现类
 *
 * @author makejava
 * @since 2023-07-26 13:59:25
 */
@Service("wenService")
public class WenServiceImpl extends ServiceImpl<WenMapper, Wen> implements WenService {

    @Override
    public List<Wen> preList(String wenContent,String wenKey, Integer currentPage, Integer pageSize) {
        List<Wen> list= this.getBaseMapper().preList(wenContent,wenKey);
        return list;
    }

    @Override
    @Transactional
    public int insert(String wenKey, String daFrom, String daContent,String avatar) {
        String daKey = UUID.randomUUID().toString();
        Da da = new Da(daKey,daContent,daFrom,new Date(System.currentTimeMillis()),avatar,0,null,"");
        Wenda wenda = new Wenda(wenKey, daKey);
        int a=this.getBaseMapper().daInsert(da);
        int b=this.getBaseMapper().wenDaInsert(wenda);

        return a>=0&&b>=0?1:0;
    }

    @Override
    public int weninsert(String wenFrom, String wenContent) {
        Wen wen = new Wen(UUID.randomUUID().toString(), wenContent, new Date(System.currentTimeMillis()), wenFrom, "0", 1,null);
        int a=this.getBaseMapper().weninsert(wen);
        return a>=0?1:0;
    }

    @Override
    public int dianZanInsert(Dianzan dianzan) {
        return this.getBaseMapper().dianZanInsert(dianzan);
    }
}
